package ae.pcfc.etks.online.itworx.ehs.web.delegate.impl;

import java.util.Date;
import java.util.List;

import ae.pcfc.etks.online.itworx.ehs.web.delegate.WorkflowDelegate;
import ae.pcfc.etks.online.itworx.ehs.web.entity.OFCRequest;
import ae.pcfc.etks.online.itworx.ehs.web.entity.OFCRequestHistory;
import ae.pcfc.etks.online.itworx.ehs.web.entity.Request;
import ae.pcfc.etks.online.itworx.ehs.web.enums.RequestAction;
import ae.pcfc.etks.online.itworx.ehs.web.enums.RequestStatus;
import ae.pcfc.etks.online.itworx.ehs.web.enums.UserType;
import ae.pcfc.etks.online.itworx.ehs.web.exception.CommunicationException;
import ae.pcfc.etks.online.itworx.ehs.web.exception.FNPServiceExpcetion;
import ae.pcfc.etks.online.itworx.ehs.web.exception.IMSException;
import ae.pcfc.etks.online.itworx.ehs.web.exception.InvalidInputException;
import ae.pcfc.etks.online.itworx.ehs.web.exception.WorkFlowException;
import ae.pcfc.etks.online.itworx.ehs.web.facade.WorkflowFacade;
import ae.pcfc.etks.online.itworx.ehs.web.model.RequestSearchCriteria;


public class WorkflowDelegateImpl extends BaseDelegateImpl implements
		WorkflowDelegate {

	/*@Override
	public List<Request> getAllRequests(String userId, String companyName,
			UserType user, Date creationDateFrom, Date creationDateTo,
			RequestStatus requestStatus, RequestField sortField,
			boolean ascending, int pageNo) {
		return serviceLocator.getFacadeService(WorkflowFacade.class)
				.getAllRequests(userId, companyName, user, creationDateFrom,
						creationDateTo, requestStatus, sortField, ascending,
						pageNo);
	}*/
	
	@Override
	public List<OFCRequest> getAllRequestsByStatus(List<RequestStatus>  requestsStatus)
	{
		return serviceLocator.getFacadeService(WorkflowFacade.class).getAllRequestsByStatus(requestsStatus);
	}

	//@Override
	/*public OFCRequest getRequestDetails(Long requestId) {
		return serviceLocator.getFacadeService(WorkflowFacade.class)
				.getRequestDetails(requestId);
	}*/

	@Override
	public List<OFCRequestHistory> getRequestHistory(Long requestId) {
		return serviceLocator.getFacadeService(WorkflowFacade.class)
				.getRequestHistory(requestId);
	}
	
	@Override
	public void createOFCRequest(OFCRequest ofcRequest)
			throws InvalidInputException, CommunicationException, RuntimeException {
		serviceLocator.getFacadeService(WorkflowFacade.class).createOFCRequest(
				ofcRequest);
	}
	
	@Override
	public int createOFCProcess(OFCRequest ofcRequest)
			throws InvalidInputException, CommunicationException, RuntimeException {
		return serviceLocator.getFacadeService(WorkflowFacade.class).createOFCProcess(ofcRequest);
	}

	@Override
	public void updateOFCRequest(OFCRequest ofcRequest) {
		serviceLocator.getFacadeService(WorkflowFacade.class).updateOFCRequest(
				ofcRequest);
	}

	@Override
	
	public boolean sendK2Mail(String processId ,String username, String actionType, OFCRequest ofcRequest, boolean isOfficer)
			throws InvalidInputException, CommunicationException, RuntimeException {
		return serviceLocator.getFacadeService(WorkflowFacade.class).sendK2Mail(processId, username, actionType, ofcRequest, isOfficer);		
	}

	@Override
	public List<Request> getActiveTasks(String processName, String userName,
			boolean isOffecier, Long requestId, RequestStatus status,
			String submissionDate) throws InvalidInputException, WorkFlowException,
			RuntimeException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Request> getAllRequests(String userName, boolean isOffecier,
			RequestSearchCriteria criteria) throws InvalidInputException,
			CommunicationException, RuntimeException {
		return serviceLocator.getFacadeService(WorkflowFacade.class).getAllRequests(userName, isOffecier, criteria);
	}
	
	public OFCRequest getDetails(Long requestId,String userId, boolean isOfficer)throws InvalidInputException, CommunicationException, RuntimeException{
		
		return serviceLocator.getFacadeService(WorkflowFacade.class).getRequestDetails(requestId,userId, isOfficer);
	}

	@Override
	public OFCRequest getRequestDetails(Long requestId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isValidOfficer(String officerId)
			throws InvalidInputException, CommunicationException, RuntimeException {
		return serviceLocator.getFacadeService(WorkflowFacade.class).isOfficer(officerId);
	}

	@Override
	public List<Request> getActiveTasks(RequestSearchCriteria searrchCriteria,
			String processName, String userName, boolean isOffecier, boolean isAssigned) throws InvalidInputException, WorkFlowException,
			CommunicationException {
		return serviceLocator.getFacadeService(WorkflowFacade.class).getActiveTasks(searrchCriteria, processName, userName, isOffecier, isAssigned);
	}

	@Override
	public long getAllRequestsSize(String userName, boolean isOfficer,
			RequestSearchCriteria searchCriteria) throws InvalidInputException,
			CommunicationException, RuntimeException {
		return serviceLocator.getFacadeService(WorkflowFacade.class).getAllRequestsSize(userName,isOfficer , searchCriteria);
	}

	@Override
	public long getAllActiveTasksSize(String processName,String userName, boolean isOfficer,
			RequestSearchCriteria searchCriteria, boolean isAssigned) throws InvalidInputException,
			CommunicationException, RuntimeException {
		return serviceLocator.getFacadeService(WorkflowFacade.class).getAllActiveTasksSize(processName,userName,isOfficer , searchCriteria, isAssigned);
	}

	@Override
	public void cancelRequest(long requestId, String username, boolean isOfficer)
			throws InvalidInputException, CommunicationException,FNPServiceExpcetion,IMSException {
		serviceLocator.getFacadeService(WorkflowFacade.class).cancelRequest(requestId, username, isOfficer);
		
	}

	@Override
	public void closeRequest(long requestId, String username, boolean isOfficer)
			throws InvalidInputException, CommunicationException,FNPServiceExpcetion,IMSException {
		serviceLocator.getFacadeService(WorkflowFacade.class).closeRequest(requestId, username, isOfficer);
		
	}
	
	public boolean manipulateRequest(OFCRequest ofcRequest,String userName,boolean isOfficer,RequestAction action)throws InvalidInputException, CommunicationException
	{
		return serviceLocator.getFacadeService(WorkflowFacade.class).manipulateRequest(ofcRequest,userName,isOfficer,action);
	}

	@Override
	public long getAllRequestsSize(String userId, String companyName,
			UserType user, Date creationDateFrom, Date creationDateTo,
			RequestStatus requestStatus) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean manipulateIMSRequest(OFCRequest ofcRequest, String userName,
			boolean isOfficer, RequestAction action, String imsStatus, Date processingDate) throws WorkFlowException{
		return serviceLocator.getFacadeService(WorkflowFacade.class).manipulateIMSRequest(ofcRequest,userName,isOfficer,action, imsStatus, processingDate);
		
	}
	@Override
	public long getActiveRequestSize(String userName){
		return serviceLocator.getFacadeService(WorkflowFacade.class).getActiveRequestSize(userName);
	}
}
